package com.gzc.just.play.last.war.robotclient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Robot AI base class
 * Corresponds to C++ version CPlayerAI
 */
public abstract class RobotAI {
    private static final Logger log = LoggerFactory.getLogger(RobotAI.class);
    
    // AI state enumeration
    public enum AIState {
        CLEARED,         // cleared state
        RUNNING,         // running state
        COMPLETE         // completed state
    }
    
    // AI state
    private AIState aiState = AIState.CLEARED;
    
    // Robot player reference
    protected final RobotPlayer player;
    
    public RobotAI(RobotPlayer player) {
        this.player = player;
    }
    
    /**
     * Begin AI
     */
    public abstract int begin();
    
    /**
     * Update AI
     */
    public abstract int update(long currentTime);
    
    /**
     * End AI
     */
    public abstract int end();
    
    /**
     * Clear AI
     */
    public int clear() {
        aiState = AIState.CLEARED;
        return 0; // return normal
    }
    
    /**
     * Get AI state
     */
    public AIState getAIState() {
        return aiState;
    }
    
    /**
     * Set AI state
     */
    public void setAIState(AIState state) {
        this.aiState = state;
    }
    
    /**
     * Get robot player reference
     */
    protected RobotPlayer getPlayer() {
        return player;
    }
    
    /**
     * Log debug message
     */
    protected void logDebug(String message, Object... args) {
        log.debug("Robot {} - AI: {}", getPlayer().getRobotId(), message, args);
    }
    
    /**
     * Log info message
     */
    protected void logInfo(String message, Object... args) {
        log.info("Robot {} - AI: {}", getPlayer().getRobotId(), message, args);
    }
    
    /**
     * Log warning message
     */
    protected void logWarn(String message, Object... args) {
        log.warn("Robot {} - AI: {}", getPlayer().getRobotId(), message, args);
    }
    
    /**
     * Log error message
     */
    protected void logError(String message, Object... args) {
        log.error("Robot {} - AI: {}", getPlayer().getRobotId(), message, args);
    }
}